package com.ruoyi.wechat.api;

import com.google.zxing.WriterException;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.wechat.domain.Goods;
import com.ruoyi.wechat.service.ICGoodsService;
import com.ruoyi.wechat.service.impl.QRCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/wechat/goods")
public class WxGoodsController extends BaseController {

    @Autowired
    private ICGoodsService cGoodsService;
    @GetMapping("/list")
    public AjaxResult list(Goods goods)
    {
        List<Goods> list = cGoodsService.selectCGoodsList(goods);
        return success(list);
    }

    @PostMapping
    public AjaxResult add(@RequestBody Goods goods)
    {
        return toAjax(cGoodsService.insertCGoods(goods));
    }


    @Anonymous
    @GetMapping("/generateQRcode")
    public void generateQRCode(@RequestParam String text,
                               @RequestParam(defaultValue = "300") int width,
                               @RequestParam(defaultValue = "300") int height,
                               HttpServletResponse response) throws WriterException, IOException {
        QRCodeService.writeQRCodeToResponse(response, text,width,height);
    }
        // 二维码图片生成)

}
